package com.means.polymerize.assembly.aspect.page;

import com.means.polymerize.common.util.ServletUtils;

/**
 * 表格数据处理
 *
 * @author xuhaifeng
 * @since 2021.10.30
 */
public class TableSupport {
    /**
     * 当前记录起始索引
     */
    public static final String PAGE_NUM = "pageNum";

    /**
     * 每页显示记录数
     */
    public static final String PAGE_SIZE = "pageSize";

    /**
     * 排序列
     */
    public static final String ORDER_BY_COLUMN = "orderByColumn";

    /**
     * 排序的方向 "desc" 或者 "asc".
     */
    public static final String ORDER_BY_MODE = "orderByMode";

    /**
     * 封装分页对象
     *
     * @return the page domain
     */
    public static PageDomain getPageDomain() {
        return PageDomain.builder()
                .pageNum(PageDomain.getPageNum(PAGE_NUM))
                .pageSize(PageDomain.getPageSize(PAGE_SIZE))
                .orderByColumn(ServletUtils.getParameter(ORDER_BY_MODE))
                .orderByColumn(ServletUtils.getParameter(ORDER_BY_COLUMN))
                .build();
    }

    /**
     * Build page request page domain.
     *
     * @return the page domain
     */
    public static PageDomain buildPageRequest() {
        return getPageDomain();
    }
}
